const mongoose = require('mongoose');

module.exports = {
    connect: (success, error) => {

        if(typeof error !== 'function'){
            error = () => console.log('连接失败');
        }
        const { mongo } = require('../config/config');
        mongoose.connect(mongo.url);
        mongoose.connection.on('error', error);
        mongoose.connection.on('close', () => console.log('关闭连接'));
        mongoose.connection.once('open', success);
    },
    mongoose: mongoose
}


